package com.subfg.common.constant;

import com.subfg.common.entity.excpetion.BusinessExceptionModel;
import com.subfg.common.util.common.StringUtil;

public enum TimeEnum {
    YEAR(1, "year"),
    QUARTER(2, "quarter"),
    MONTH(3,"month"),
    WEEK(4, "week"),
    DAY(5, "day"),
    HOUR(6,"hour"),
    MINUTE(7,"minute"),
    SECOND(8,"second")
    ;

    private Integer value;
    private String timeType;

    TimeEnum(Integer value, String timeType) {
        this.value = value;
        this.timeType = timeType;
    }

    public Integer getValue() {
        return value;
    }

    public String getTimeType() {
        return timeType;
    }
    // 根据值数值类型
    public static TimeEnum getValueTimeEnum(Integer value) {
        if (value != null) {
            for (TimeEnum timeEnum : TimeEnum.values()) {
                if (timeEnum.getValue().equals(value)) {
                    return timeEnum;
                }
            }
        }
        return TimeEnum.MONTH;
    }
    // 根据所给字符
    public static TimeEnum getTimeTypeEnum(String timeType) throws BusinessExceptionModel {
        if (!StringUtil.isEmpty(timeType)) {
            for (TimeEnum timeEnum : TimeEnum.values()) {
                if (timeEnum.getTimeType().equals(timeType)) {
                    return timeEnum;
                }
            }
        }
        throw new BusinessExceptionModel();
    }
}
